package com.lwj.liwanjia.presenter;

import com.lwj.liwanjia.bean.AddressBean;
import com.lwj.liwanjia.impl.AddressView;
import com.lwj.liwanjia.model.AddressModel;

import rx.Subscriber;

/**
 * Created by Administrator on 2017/10/10.
 */

public class AddressPresenter {
    private AddressView addressView;
    private AddressModel addressModel;

    public AddressPresenter(AddressView addressView) {
        this.addressView = addressView;
        addressModel = new AddressModel();
    }

    public void getAddressData(String token) {
        if (addressView != null) {
            addressModel.getAddressData(token, new Subscriber<AddressBean>() {
                @Override
                public void onCompleted() {
                    addressView.hideProgress();
                }

                @Override
                public void onError(Throwable e) {
                    addressView.showError((Exception) e);
                    addressView.hideProgress();
                }

                @Override
                public void onNext(AddressBean addressBean) {
                    addressView.getAddressData(addressBean);
                }

                @Override
                public void onStart() {
                    super.onStart();
                    addressView.showProgress();
                }
            });
        }
    }
}
